package com.mz.mattress.client.api.biz;

import com.mz.mattress.api.util.JacksonUtils;
import com.mz.mattress.client.api.resp.DeviceStatusResp;
import com.mz.mattress.client.timer.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/websocket")
public class WebSocketController {

    @Autowired
    private WebSocketServer webSocketServer;

    @GetMapping("/send/{memberId}/{val}")
    public void send(@PathVariable Long memberId, @PathVariable Integer val) {

        DeviceStatusResp resp = new DeviceStatusResp();
        resp.setId(3);
        resp.setDeviceCode("67738bd8353aa6e11d5c96a3");
        resp.setSignal(2);
        resp.setOnline(1);
        resp.setWorkMode(3);
        resp.setWorkStatus(1);
        resp.setTemper(33);
        resp.setTemperCur(val);
        resp.setStrength(8);
        resp.setVolume(9);

        resp.setRate(111);
        resp.setOxygen(55);
        resp.setCycle(99);
        resp.setTired(28);
        resp.setResults(val);
        resp.setInspectStatus(val);

        webSocketServer.sendOneMessage(memberId.toString(), JacksonUtils.toJson(resp));
    }

}
